package com.lightheart.sphr.xiaobinggan.blackandwhite.ui;


import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RadioButton;

import com.lenebf.android.app_dress.AppDress;
import com.lenebf.android.app_dress.color.EyeProtectionColor;
import com.lenebf.android.app_dress.color.GrayColor;
import com.lenebf.android.app_dress.color.NightColor;
import com.lightheart.sphr.xiaobinggan.R;
import com.lightheart.sphr.xiaobinggan.base.BaseActivity;
import com.lightheart.sphr.xiaobinggan.blackandwhite.uitls.AppSetting;
/**
 * https://www.yuque.com/lenebf/fl1svo/sagoxt
 * https://github.com/lenebf/AppDress
 * **/
public class BlackAndWhiteActivity extends BaseActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_black_and_white;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        View.OnClickListener radioButtonClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.rb_gray: {
                        AppDress.tint(new GrayColor());
                        AppSetting.setDressColor(getApplicationContext(), AppSetting.COLOR_BLACK_WHITE);
                        break;
                    }
                    case R.id.rb_eye_protection: {
                        AppDress.tint(new EyeProtectionColor(0.3f));
                        AppSetting.setDressColor(getApplicationContext(), AppSetting.COLOR_EYE_PROTECTION);
                        break;
                    }
                    case R.id.rb_night_mode: {
                        AppDress.tint(new NightColor());
                        AppSetting.setDressColor(getApplicationContext(), AppSetting.COLOR_NIGHT_MODE);
                        break;
                    }
                    default: {
                        AppDress.tint(null);
                        AppSetting.setDressColor(getApplicationContext(), AppSetting.COLOR_NONE);
                        break;
                    }
                }
            }
        };
        RadioButton noneButton = findViewById(R.id.rb_none);
        noneButton.setOnClickListener(radioButtonClickListener);
        RadioButton grayModeButton = findViewById(R.id.rb_gray);
        grayModeButton.setOnClickListener(radioButtonClickListener);
        RadioButton eyeProtectModeButton = findViewById(R.id.rb_eye_protection);
        eyeProtectModeButton.setOnClickListener(radioButtonClickListener);
        RadioButton nightModeButton = findViewById(R.id.rb_night_mode);
        nightModeButton.setOnClickListener(radioButtonClickListener);
        int colorValue = AppSetting.getDressColor(getApplicationContext());
        if (AppSetting.COLOR_BLACK_WHITE == colorValue) {
            grayModeButton.setChecked(true);
        } else if (AppSetting.COLOR_EYE_PROTECTION == colorValue) {
            eyeProtectModeButton.setChecked(true);
        } else if (AppSetting.COLOR_NIGHT_MODE == colorValue) {
            nightModeButton.setChecked(true);
        } else {
            noneButton.setChecked(true);
        }
    }

}